﻿@model List<Style>

@{
    var strHp = new StringHelper();

    float listPrice = ViewBag.ListPrice ?? 0;
    float vndExchange = 23000;
}

@if (Model.Count == 0)
{
    <h2 class="text-danger">
        Cập nhật sau
    </h2>
}
else if (Model.Count == 1)
{
    Style style = Model.First();

    <div class="form-group form-price">
        <span class="list-price">
            @strHp.PriceFormat(listPrice, "usd")
        </span>
        <span class="chomy-price">
            @strHp.PriceFormat(style.UnitPrice, "usd")
        </span>
        <span class="vnd-price">
            @strHp.PriceFormat(style.UnitPrice * vndExchange, "vnd")
        </span>
    </div>

    <div class="form-group">
        @if (style.Quantity > 0)
        {
            if (Request.IsAuthenticated)
            {
                <button type="button" class="btn btn-primary" onclick="new ShoppingCart().Add(this, @style.Id)">
                    <i class="fa fa-shopping-cart"></i> Thêm vào giỏ hàng
                </button>
            }
            else
            {
                <a href="@Url.Action("Login", "Account", new { returnUrl = Request.Url.LocalPath })" class="btn btn-primary">
                    <i class="fa fa-shopping-cart"></i> Thêm vào giỏ hàng
                </a>
            }
        }
        else
        {
            <strong class="text-danger">Tạm hết hàng</strong>
        }
    </div>
}
else
{
    float min = Model.Min(x => x.UnitPrice);
    float max = Model.Max(x => x.UnitPrice);

    <div class="form-group form-price">
        <span class="list-price">
            @strHp.PriceFormat(listPrice, "usd")
        </span>
        @if (min != max)
        {
            <span class="chomy-price">
                @strHp.PriceFormat(min, "usd") - @strHp.PriceFormat(max, "usd")
            </span>

        }
        else
        {
            <span class="chomy-price">
                @strHp.PriceFormat(min, "usd")
            </span>
            <span class="vnd-price">
                @strHp.PriceFormat(min * vndExchange, "vnd")
            </span>
        }
    </div>

    <div class="form-group">
        @if (Request.IsAuthenticated)
        {

            <button type="submit" class="btn btn-primary">
                <i class="fa fa-shopping-cart"></i> Thêm vào giỏ hàng
            </button>
        }
        else
        {
            <a href="@Url.Action("Login", "Account", new { returnUrl = Request.Url.LocalPath })" class="btn btn-primary">
                <i class="fa fa-shopping-cart"></i> Thêm vào giỏ hàng
            </a>
        }
    </div>
}